const app = getApp();
const utils = require('../../../utils/utils.js');
let PAGE = {page: 1, page_size: 10};
Page({
  data: {
    list: [],
    total: 0,
  },
  onLoad: function (options) {
    let proxuUser = app.globalData.proxuUser;
    console.log(JSON.stringify(proxuUser));
    if (proxuUser.accountId == null) {
      wx.reLaunch({
        url: '../../tx/login/login'
      })
    }
    wx.showLoading({
      title: 'loading...',
        mask: true
    });
    PAGE = {page: 1, page_size: 10};
    // 获取用户使用记录信息
    this.getTxList();
    wx.hideLoading();
  },
  // 提现列表数据
  getTxList(){
    let that = this;
    let newList = [];
    let oldList = that.data.list;
    let proxuUser = app.globalData.proxuUser;
    let accountId = proxuUser.accountId;
    let accountType = proxuUser.accountType;
    if (accountId == null) {
      accountId = 0;
    }
    if (accountType == null) {
      accountType = 0;
    }
    utils.AppHttpRequest('/common/getWithdrawal', {
      id: accountId,
      accountType: accountType,
      pageNum: PAGE.page,
      pageSize: PAGE.page_size
    }, function (res) {
        if (res.code == 0) {
          console.log(JSON.stringify(res));
          that.setData({
            total: res.total
          })
          if (PAGE.page > 1) {
              newList = res.rows;
              that.setData({
                  list: oldList.concat(newList)
              })
          } else {
              that.setData({
                  list: res.rows
              })
          }
        }
    })
  },
  // ========================= 刷新下一页 ====================
  onReachBottom() {
    let that = this;
    if (that.data.total > that.data.list.length) {
        PAGE.page++;
        that.getTxList();
    } else {
        return
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})